﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AAA.Meta.Chart.Data
{
    public class BarDataExtra
    {
        private List<string> _lstTitle;
        private List<string> _lstField;
        private Dictionary<string, List<object>> _dicExtraInfo;

        public BarDataExtra()
        {
            Clear();
        }

        public void ClearData()
        {
            foreach (string strKey in _dicExtraInfo.Keys)
                _dicExtraInfo[strKey].Clear();
        }

        public void Clear()
        {
            _lstTitle = new List<string>();
            _lstField = new List<string>();
            _dicExtraInfo = new Dictionary<string, List<object>>();
        }

        public void SetField(List<string> lstField)
        {
            SetField(lstField, lstField);
        }

        public void SetField(List<string> lstField, List<string> lstTitle)
        {
            Clear();
            for(int i = 0; i < lstTitle.Count; i++)
            {
                _lstTitle.Add(lstTitle[i]);
                _lstField.Add(lstField[i]);
                _dicExtraInfo.Add(lstField[i], new List<object>());
            }
        }

        public List<string> GetFieldName()
        {
            return _lstField;
        }

        public List<string> GetTitle()
        {
            return _lstTitle;
        }

        public void AddData(List<object> lstInfo)
        {
            if (lstInfo.Count != _lstField.Count)
                return;

            for (int i = 0; i < _lstField.Count; i++)
            {
                _dicExtraInfo[_lstField[i]].Add(lstInfo[i]);
            }
        }

        public int GetRecordCount()
        {
            return _lstField.Count > 0 ? _dicExtraInfo[_lstField[0]].Count : 0;
        }

        public List<object> GetData(string strField)
        {
            if (_dicExtraInfo.ContainsKey(strField) == false)
                return null;

            return _dicExtraInfo[strField];
        }

        public List<object> GetInfo(int iIndex)
        {
            List<object> lstReturn = new List<object>();

            for(int i = 0; i < _lstField.Count; i++)
                lstReturn.Add(GetInfo(_lstField[i], iIndex));

            return lstReturn;
        }

        public object GetInfo(string strField, int iIndex)
        {
            if (_dicExtraInfo.ContainsKey(strField) == false)
                return null;

            try
            {
                return _dicExtraInfo[strField][iIndex];
            }
            catch (Exception ex)
            {
            }
            return null;
        }

    }
}
